// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors, sized_box_for_whitespace, avoid_unnecessary_containers, avoid_print

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mybase/base/abstract/IFFR.dart';
import 'package:mybase/base/abstract/IFFRefresh.dart';
import 'package:mybase/base/abstract/IFFScaffold.dart';
import 'package:mybase/base/widget/layout/FFLineContainer.dart';
import 'package:mybase/base/widget/layout/FFNavi.dart';
import 'package:mybase/base/widget/layout/FFTextButton.dart';
import 'package:mybase/base/widget/page/FFScaffold.dart';
import 'package:mybase/base/tool/extension/FFListExt.dart';

class AnimatorPage extends FFScaffold {
  String? name;

  AnimatorPage({
    Key? key,
    this.name,
  }) : super(key: key);

  @override
  AnimatorPageState createState() => AnimatorPageState();
}

class AnimatorPageState extends FFScaffoldState with MFFScaffold {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;

  @override
  AnimatorPage get widget => super.widget as AnimatorPage;

  @override
  // TODO: implement ffPageStatus
  FFPageStatus? get ffPageStatus => FFPageStatus.result;

  /**固定写法end */

  late Animation<double> animation;
  late AnimationController controller;

  @override
  void ffInitState() {
    super.ffInitState();

    controller = AnimationController(duration: const Duration(milliseconds: 300), vsync: this);
    Animation<double> curve = CurvedAnimation(parent: controller, curve: Curves.ease);

    animation = Tween(begin: 0.0, end: 1.0).animate(curve)
      ..addListener(() {
        setState(() => {});
      });

    //启动动画(正向执行)
    controller.forward();
  }

  @override
  void ffDispose() {
    //在super.dispose()之前销毁才行
    controller.dispose();
    super.ffDispose();
  }

  @override
  Widget? ffNavi(BuildContext context) {
    return FFNaviFast.navi(context, "测试动画", color: Colors.white);
  }

  @override
  Widget? ffBody(BuildContext context) {
    List<Widget> slivers = [
      SliverToBoxAdapter(
        child: Container(
          child: FFLineContainer(
            children: [
              FFTextButton(
                padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                unconstrainedBox: true,
                text: "动画放大效果",
                color: Colors.pink,
                onClick: () {
                  controller.forward();
                },
              ),
              FFTextButton(
                padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                unconstrainedBox: true,
                text: "动画缩小效果",
                color: Colors.pink,
                onClick: () {
                  controller.reverse();
                },
              ),
              Container(
                width: 100.w,
                height: 100.w * animation.value,
                color: Colors.blue,
                child: CustomScrollView(
                  slivers: [
                    SliverList(
                      delegate: SliverChildBuilderDelegate(
                        (BuildContext ctx, int index) {
                          return Container(
                            height: 50.w,
                            margin: EdgeInsets.only(top: 1.w),
                            color: Colors.red,
                          );
                        },
                        childCount: 2,
                      ),
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    ];
    return CustomScrollView(slivers: slivers);
  }
}
